package com.example.myapplication.ui.activity.square

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.myapplication.request.CollectRequest
import com.example.myapplication.request.SquareRequest
import kotlinx.coroutines.launch

/**
 *用户分享的viewModel
 *
 * @author : Kun
 * @date : 2021/6/10
 * @time : 11:35
 */
class UserSharedViewModel : ViewModel() {
    /**
     * 分享的request
     */
    val squareRequest = SquareRequest()

    /**
     * 收藏相关的request
     */
    val collectRequest = CollectRequest()

    /**
     * 请求用户分享数据
     */
    fun requestUserShared(userId: Int, index: Int) {
        viewModelScope.launch {
            squareRequest.requestUserShared(userId, index)
        }
    }
    /**
     * 请求个人分享数据
     */
    fun requestMyShared(index: Int) {
        viewModelScope.launch {
            squareRequest.requestMyShared( index)
        }
    }

    /**
     * 删除分享文章
     */
    fun requestDeleteShared(id: Int) {
        viewModelScope.launch {
            squareRequest.requestDeleteShared(id)
        }
    }

    /**
     * 新增文章收藏
     */
    fun requestAddCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestAddCollectArticle(id)
        }
    }

    /**
     * 取消文章收藏
     */
    fun requestDelCollectArticle(id: Int) {
        viewModelScope.launch {
            collectRequest.requestDelCollectArticle(id)
        }
    }
}